home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / buffr2.zip / BHPTEST.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  2KB  |  76 lines

  1. Program BufferedHeapTest;
  2.  
  3. {NOTE: There are two bits of code inserted into the BGenHeap unit
  4.        for no useful reason other then the display during this
  5.        test program's run.  One is in the Uses clause, and the
  6.        other is in the Sort method.  Delete these before using
  7.        the unit for any production code! }
  8.  
  9. Uses BHeaps,Crt;
  10.  
  11. Const
  12.   Num = 100000;
  13.  
  14. Var
  15.   H : RealHeap;
  16.   I : LongInt;
  17.   R : Real;
  18.  
  19. Begin
  20.   ClrScr;
  21.   Randomize;
  22.  
  23.   WriteLn (MemAvail,' Bytes Available before Initialization.');
  24.  
  25.   H.Create;
  26.   H.Init(Num,0,'Heap.Dat');
  27.  
  28.   WriteLn (MemAvail,' Bytes Available after Initialization.');
  29.   WriteLn ('Object Occupies ',SizeOf(H),' Bytes.');
  30.   WriteLn;
  31.   Write ('SORTING ',Num,' FLOATING POINT NUMBERS.');
  32.  
  33.   For I := 1 to Num do
  34.     Begin
  35.       R := 1000000000*Random;
  36.       If Random(2) = 1 Then R := -R;
  37.       GoToXY (1,7);
  38.       Write ('Sifting Up ',I,'th Element.');
  39.       H.SiftUp (R,I)
  40.     End;
  41.  
  42.   GoToXY (1,7);
  43.   Write ('Finished Sifting ',Num,' Elements. Press Return to Continue...');
  44.   ReadLn;
  45.   WriteLn ('Storing Heap to Disk File...');
  46.  
  47.   H.Store;
  48.  
  49.   WriteLn ('MemAvail after Storing = ',MemAvail);
  50.   Write ('Press Return to Continue...');
  51.   ReadLn;
  52.   WriteLn ('Loading Heap from Disk File...');
  53.  
  54.   H.Load ('Heap.Dat',MemAvail);
  55.  
  56.   WriteLn ('MemAvail after Loading = ',MemAvail);
  57.   Write ('Press Return to Continue...');
  58.   ReadLn;
  59.  
  60.   GoToXY (1,15);
  61.   Write ('Sorting Element # ');
  62.  
  63.   H.Sort;
  64.  
  65.   WriteLn;
  66.   Write ('Done Sorting. Press Return to Continue...');
  67.  
  68.   ReadLn;
  69.  
  70.   For I := 1 to Num do WriteLn (H.Retrieve(I):5:5,' was the ',I,'th Element');
  71.  
  72.   ReadLn;
  73.  
  74.   H.Destroy;
  75.  
  76. End.